<template>
	<view class="content">
		<view class="search">
			<uni-easyinput trim="all" v-model="formData.key" placeholder="请输入电话、ID、名称搜索" />
			<view class="btn" @click="searchUserList">
				搜索
			</view>
	  	</view>

		<view class="total flex flex-column">
			<view class="flex flex-column" style="font-size: 12px;">
				<view class="flex">
					<view class="w-50">总注册：{{sumData.register}}</view>
					<view class="w-50">总关注：{{sumData.follow}}</view>
				</view>
				<view class="flex">
					<view class="w-50">总订单：{{sumData.ordercount}}</view>
					 <view class="w-50">总流水：{{sumData.money}}¥</view>
				</view>
			</view>
			<view class="flex just-b m-t-10" style="font-size: 12px;">
				<view class="flex flex-align-center">时间：
				<view style="border-bottom: 1px solid;padding: 0px 10px;">
					<uni-datetime-picker v-model="range" type="daterange" @change="maskClick">
					{{formData.start}} ~ {{formData.end}}
					</uni-datetime-picker>
				</view>
				</view>
				<view @click="changePage" style="border: 1px solid green;border-radius: 8px;padding: 0px 30rpx;">
					<uv-text align="center" size="12" type="success" text="查看"></uv-text>
				</view>
			</view>
	  	</view>

		<view class="channel-content p-10">
			<view class="table">
				<view class="row header">
					<view class="cell"> ID </view>
					<view class="cell">
						<text>姓名</text>
						<text>比例</text>
					</view>
					<view class="cell" style="width: 110px">
						<text>状态</text>
						<text>注册日期</text>
					</view>
					<view class="cell">
						<text>分成</text>
						<text>余额</text>
					</view>
					<view class="cell"> 操作 </view>
				</view>
			</view>
			<uv-skeletons v-for="(_, index) in Array(10)" :key="index" :loading="loading" :skeleton="skeleton"></uv-skeletons>
			<view class="table-content">
				<view class="table">
					<view class="row body" v-for="item in list" :key="item.id">
						<view class="cell status_0"> {{ item.id }} </view>
						<view class="cell">
							<!-- <uv-input v-if="isEdit && item.id === userItme.id" v-model="userItme.realname" placeholder="请输入名字"
								style="padding: 0;" @confirm="changeHandle"></uv-input> -->
							<text @touchend="maskTouchend(item)" @click="maskTouchend(item)">{{ item.realname }}</text>
							<text>{{ item.channel_rate }}%</text>
						</view>
						<view class="cell" style="width: 110px">
							<text>{{ item.is_freeze === 1 ? '冻结' : '正常' }}</text>
							<text>{{ totime_day(item.create_time * 1000) }}</text>
						</view>
						<view class="cell">
							<text>{{ item.cumulative_brokerage }}</text>
							<text>{{ item.brokerage }}</text>
						</view>
						<view class="cell" @click="getChannelData(item)"> 查看 </view>
					</view>
					<uv-empty v-if="isNotEmpty" mode="order" icon="../../static/empty.png"></uv-empty>
				</view>
			</view>
		</view>

		<view class="page">
			<view class="page-item">
			<pagination :data="pageInfo" @page="changePage"></pagination>
		</view>
		</view>
	</view>
</template>

<script>
	import { totime_day } from '@/utils/index'
	import pagination from '@/components/pagination.vue'
	export default {
		data() {
			return {
				range: '',
				list: [],
				loading: false,
				isNotEmpty: false,
				formData: {
					start: '',
					end: '',
					key: ''
				},
				pageInfo: {
					total: 0,
					per_page: 0,
					last_page: 0,
					current_page: 1
				},
				sumData: {},
				skeleton: [{
					type: 'line',
					num: 1,
					gap: '20rpx',
					style: ['height: 100rpx;margin-bottom: 10px']
				}]
			}
		},
		components: {
			pagination
		},
		onLoad() {
			this.getChannelList()
		},
		methods: {
			totime_day,
			getChannelData(item){
				uni.navigateTo({ url: "/pages/channel/index?id=" + item.id })
			},
			maskClick(e){
				let [start, end] = e
				this.formData.start = start
				this.formData.end = end
			},
			searchUserList(){
				this.getChannelList({page: 1})
			},
			changePage(val){
				console.log('val', val);
				
				this.pageInfo.current_page = val
				this.list = []
				this.getChannelList()
			},
			getChannelList(formData){
				this.loading = true
				let params = {
					key: this.formData.key,
					start: this.formData.start,
					end: this.formData.end,
					page: this.pageInfo.current_page
				}
				if(formData){
					params = {
						...params,
						...formData
					}
				}
				this.$http.http("masterchannel/index/channelist", params, "POST").then(res=>{
					this.loading = false
					this.list = res.data.data
					this.pageInfo.total = res.data.total
					this.pageInfo.per_page = res.data.per_page
					this.pageInfo.last_page = res.data.last_page
					this.pageInfo.current_page = res.data.current_page

					if(res.data.sum){
						const [follow, register] = res.data.sum.reg.split('/')
						this.sumData = {
							...res.data.sum,
							register,
							follow,
							money: parseFloat(res.data.sum.money).toFixed(2)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.channel-content {
		background-color: #ffffff;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		padding: 8px;
		margin: 8px;
		border-radius: 8px;

		overflow: hidden;

		height: calc(100vh -  64rpx - 280rpx - 74rpx);
		border-radius: 8px;
		box-sizing: border-box;
		background-color: #fff;

		.table-content {
			overflow: scroll;
			height: calc(100% - 65px);
		}
	}

	.table {
		display: table;
		width: 100%;
		overflow: hidden;
		border-collapse: collapse;
		table-layout: fixed;

		.row {
			display: table-row;
			border-bottom: #dddddd 1px solid;

			.cell {
				display: table-cell;
				text-align: center;
				vertical-align: middle;
				padding: 8px 0;
			}

			.cell>text {
				display: block;
			}

			.cell>text:nth-child(2) {
				padding-top: 4px;
			}
		}

		.body {
			.cell {
				font-size: 12px;
			}

			.cell>text:nth-child(1) {
				padding-bottom: 4px;
				border-bottom: 1px solid #f0f0f0;
			}
		}

		.header {
			color: #2d8cf0;
			font-size: 14px;
			background-color: #fafafa;

			.cell>text:nth-child(1) {
				padding-bottom: 4px;
				border-bottom: 1px solid #fff;
			}
		}

		.status_0 {
			color: #38987c;
		}
	}

	.search{
		height: 64rpx;
		background-color: #ffffff;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		padding: 8px;
		margin: 8px;
		border-radius: 8px;

		display: flex;
		align-items: center;

		.btn{
			color: #007aff;
			margin-left: 20rpx;
		}

		.uni-easyinput{
		border-bottom: 1px solid #dcdfe6;
		}
	
		:deep(.uni-easyinput .uni-easyinput__content){
		// border-bottom: 1px solid #dcdfe6;
		border: none;
		}
	}

	.total{
		height: 100rpx;
		background-color: #ffffff;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		padding: 8px;
		margin: 8px;
		border-radius: 8px;
		.btn{
			color: #007aff;
			margin-left: 20rpx;
		}
	}

  .flex{
	display: flex;
  }
  .just-b{
	justify-content: space-between;
  }
  .m-t-10{
	margin-top: 10rpx;
  }
  .flex-column{
	flex-direction: column;
  }
  .w-50{
	width: 50%;
  }

  .page {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100vw;
  padding: 8px 0;
  background-color: #fff;
  border-top: #dddddd 1px solid;
  .page-item {
    width: 95vw;
    margin: 0 auto;
  }
}
</style>